package br.com.gerenciamento.pg.framework.mail;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessagePreparator;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;



@Component
public class AsyncEmailSender {

	private static final Logger LOGGER = LoggerFactory.getLogger(AsyncEmailSender.class);
	
	@Async
	public void sendEmail(JavaMailSender mailSender, final MimeMessagePreparator preparator, final EmailMessage emailMessage) {
		mailSender.send(preparator);
		LOGGER.info("Async email sent '{}' to: {}", emailMessage.getSubject(), emailMessage.getTo());
	}

}
